package com.tanhua.admin.task;

import com.tanhua.admin.service.AnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @program: tanhua
 * @description:
 * @author: MR.peng
 * @create: 2022-03-31 16:35
 **/
/*
 *   定时任务类
 *       1.类交给容器管理
 *       2.编写定时执行的java方法，没有参数，没有返回值
 * */

@Component
public class AnalysisTask {


    @Autowired
    private AnalysisService analysisService;

    //每小时统计日志表数据写入到统计表
    //@Scheduled(cron = "0/5 * * * * ? ")
    @Scheduled(cron = "0 0 0/1 * * ? ")
    public void analysis() throws ParseException {
        String now = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
        System.out.println("当前时间"+now);
        //调用service完成数据统计
        analysisService.analysis();
    }
    /**
     * 恢复次数
     */
//    @Scheduled(cron = "0/20 * * * * ?")
    @Scheduled(cron = "0 0 0 * * ?")
    public void regain (){
        System.out.println("系统时间: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        analysisService.regain ();
    }

    /**
     * 删除以拾取的语音
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void delVoice (){
        System.out.println("系统时间: " + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
        analysisService.delVoice ();
    }
}
